/*******************************************************************************
 * Copyright (c) 2011 Jovansonlee B. Cesar.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Jovansonlee B. Cesar - initial API and implementation
 ******************************************************************************/
package com.ivanceras.server.util;

import java.util.Arrays;

import com.ivanceras.shared.exception.IvancerasException;

public class CStringUtils {
	public static String toVariableName(String var){
		String char1 = var.substring(0, 1);
		String rest = var.substring(1, var.length());
		char1 = char1.toLowerCase();
		return char1+rest;
	}
	public static String capitalize(String var){
		String char1 = var.substring(0, 1);
		String rest = var.substring(1, var.length());
		char1 = char1.toUpperCase();
		return char1+rest;
	}
	
	public static String beautify(String str){
		str = str.replace("_", " ");
		str = str.replace("-", " ");
		str = capitalize(str);
		return str;
	}
	
	public static int indexOf(String[] attributes, String attribute){
		for(int i = 0; i < attributes.length; i++){
			if(attribute.equals(attributes[i])){
				return i;
			}
		}
		try {
			throw new IvancerasException("Attribute ["+attribute+"] not found! in "+Arrays.asList(attributes));
		} catch (IvancerasException e) {
			e.printStackTrace();
		}
		return -1;
	}
}
